# to do: output and display palettes
#kargs = {k:widgets.Dropdown(options=v, value=v[0], disabled=False, layout=Layout(width='auto')) for k,v in variant_ranges.items()}
#kargs['i'] = widgets.IntSlider(min=1, max=40, step=1, value=1, continuous_update=False, readout=True, readout_format='d')
n_imgs_per_group = 40
kargs = {k:pn.widgets.DiscreteSlider(name=k, options=list(v), value=v[0]) for k,v in variant_ranges.items()}
kargs['i'] = pn.widgets.IntSlider(name='i', start=1, end=n_imgs_per_group, step=1, value=1)
PRELOAD_IMAGES = False
from PIL import Image
def read_image(fpath):
#return plt.imread(fpath)
#return pn.pane.PNG(fpath, width=700)
with Image.open(fpath) as _img:
img = _img.copy()
return img
url_prefix = "https://raw.githubusercontent.com/dmarx/pytti-settings-test/main/images_out/"
#im_path = im_path.replace('images_out/', url_prefix)
image_paths = [str(p) for p in Path('images_out').glob('**/*.png')]
#print(len(list(image_paths)))
d_image_urls = {im_path:im_path.replace('images_out/', url_prefix) for im_path in image_paths}
if PRELOAD_IMAGES:
d_images = {}
for folder in df_meta['fpath']:
for im_path in folder.glob('*.png'):
d_images[str(im_path)] = read_image(im_path)
#@widgets.interact(
@pn.interact(
**kargs
)
#@pn.interact
def display_images(
palettes,
palette_size,
gamma,
hdr_weight,
smoothing_weight,
palette_normalization_weight,
i,
):
folder = df_meta[
(palettes == df_meta['palettes']) &
(palette_size == df_meta['palette_size']) &
(gamma == df_meta['gamma']) &
(hdr_weight == df_meta['hdr_weight']) &
(smoothing_weight == df_meta['smoothing_weight']) &
(palette_normalization_weight == df_meta['palette_normalization_weight'])
]['fpath'].values[0]
im_path = str(folder / f"{folder.name}_{i}.png")
im_url = d_image_urls[im_path]
#return Image(im_path, width=700)
#print(type(im_path))
#im = im_path
#url_prefix = "https://raw.githubusercontent.com/dmarx/pytti-settings-test/main/images_out/"
#im_path = im_path.replace('images_out/', url_prefix)
#print(im_path)
#if PRELOAD_IMAGES:
# im = d_images[im_path]
#else:
# im = im_path
#return pn.pane.PNG(im, width=700)
#return im
#return pn.pane.PNG(im_url, width=700)
return pn.pane.HTML(f'<img src="{im_url}" width="700">')
# embedding this makes the page nearly a gigabyte in size.
# need to use a CDN of something like that.
pn.panel(display_images).embed(max_opts=n_imgs_per_group, max_states=999999999)
#pn.panel(display_images)
#display_images